//@author A0083782W

//IndexTranslator is used to form a mapping between the displayed
//index and actual storage index
//use setMapping to set the mapping
//deleteMapping will remove the entry and adjust the storage accordingly.

#pragma once

#include "CommonDataType.h"
#include "ThrowErrorCode.h"
#include <vector>

using CommonDataType::pos_int;
using std::vector;

class IndexTranslator;

struct MAPPING_UNIT{
private:
	pos_int storageIndex;
	pos_int displayIndex;
	void reset();
	MAPPING_UNIT();

	friend IndexTranslator;
};

class IndexTranslator {

protected:
	vector<MAPPING_UNIT> _myMappingData; 
	bool _illegalInput;
	bool isRepeatation ();
	void sort ();
	void update (pos_int deletedIndex);

public:
	void reset ();
	IndexTranslator ();
	IndexTranslator (const vector<pos_int>& displayedIndices);

	void setMapping (const vector<pos_int>& displayedIndices);
	bool deleteMapping (pos_int displayedIndex);
	
	int getStorageIndex (const pos_int displayedIndex) const;
	bool isExecutable () const;
};



